<?php

declare(strict_types=1);

namespace App\Entity;

use App\Models\Product;

class ProductNewEntity extends ABaseEntity
{
    public function __construct(Product $model = null)
    {
        if ($model === null) {
            $model = new Product();
        }
        $this->model = $model;
    }

    public function __clone()
    {
        $this->model = clone $this->model;
    }

    /**
     * @return int
     */
    public static function getProductIdByBtype(string $btype)
    {
        if (empty(explode(',', $btype))) {
            return 0;
        }

        $model = Product::where('btype', $btype)->first();
        if ($model === null) {
            return 0;
        }

        return $model->id;
    }

    /**
     * @return Product
     */
    public static function getNewModelInstance()
    {
        $productModel                           = new Product();
        $productModel->btype                    = 0;
        $productModel->product_category_id      = 0;
        $productModel->product_desc             = '';
        $productModel->product_menu_image       = '';
        $productModel->description              = '';
        $productModel->image                    = '';
        $productModel->order_image              = '';
        $productModel->title                    = '';
        $productModel->price                    = 0;
        $productModel->old_price                = 0;
        $productModel->on_sale                  = 0;
        $productModel->product_open_city_config = Product::CLOSE_CITY_CONFIG;

        return $productModel;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return (int) $this->model->id;
    }

    /**
     * @return int
     */
    public function getOnSale()
    {
        return $this->model->on_sale;
    }

    public function setOnSale(int $value)
    {
        $this->model->on_sale = $value;
    }

    /**
     * @return int
     */
    public function getBType()
    {
        return (int) $this->model->btype;
    }

    public function setBType(int $val)
    {
        $this->model->btype = $val;
    }

    /**
     * @return string
     */
    public function getTitle()
    {
        return (string) $this->model->title;
    }

    public function setTitle(string $title)
    {
        $this->model->title = $title;
    }

    /**
     * @return string
     */
    public function getImage()
    {
        return ImageTool::groupImageUrl((string) $this->model->image);
    }

    public function setImage(string $image)
    {
        $this->model->image = $image;
    }

    /**
     * @return string
     */
    public function getOrderImage()
    {
        return returnImage((string) $this->model->order_image);
    }

    public function setOrderImage(string $value)
    {
        $this->model->order_image = $value;
    }

    /**
     * @return string
     */
    public function getProductMenuImage()
    {
        return ImageTool::groupImageUrl((string) $this->model->product_menu_image);
    }

    public function setProductMenuImage(string $value)
    {
        $this->model->product_menu_image = $value;
    }

    /**
     * @return string
     */
    public function getProductDesc()
    {
        return (string) $this->model->product_desc;
    }

    public function setProductDesc(string $value)
    {
        $this->model->product_desc = $value;
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return (string) $this->model->description;
    }

    public function setDescription(string $value)
    {
        $this->model->description = $value;
    }

    /**
     * @return string
     */
    public function getPrice()
    {
        return $this->model->price ?: '0';
    }

    /**
     * @return string
     */
    public function getOldPrice()
    {
        return $this->model->old_price ?: '0';
    }

    public function setProductShowType(int $val)
    {
        $this->model->product_show_type = $val;
    }

    /**
     * @return int
     */
    public function getProductShowType()
    {
        return $this->model->product_show_type;
    }

    /**
     * @return mixed
     */
    public function getProductCity()
    {
        return $this->model->product_city;
    }

    /**
     * @return string
     */
    public function getProductBuyNumLeftDesc()
    {
        return (string) $this->model->product_buy_num_left_desc;
    }

    /**
     * @return int
     */
    public function getProductCategoryId()
    {
        return $this->model->product_category_id;
    }

    public function setProductCategoryId(int $value)
    {
        $this->model->product_category_id = $value;
    }

    /**
     * @return int
     */
    public function getProductOpenCityConfig()
    {
        return $this->model->product_open_city_config;
    }

    public function setProductOpenCityConfig(int $val)
    {
        $this->model->product_open_city_config = $val;
    }

    /**
     * @return string
     */
    public function getSpecification()
    {
        return $this->model->specification;
    }

    public function setSpecification(string $value)
    {
        $this->model->specification = $value;
    }

    public function getLeastServiceMinute(): int
    {
        return (int) $this->model->least_service_minute;
    }

    public function setLeastServiceMinute(int $least_service_minute): void
    {
        $this->model->least_service_minute = $least_service_minute;
    }
}
